<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>queue全部方法demo</title>
<script src="http://g.tbcdn.cn/kissy/k/1.4.2/seed-min.js" charset="utf-8"></script>
</head>
<body>
<h2>queue全部方法demo</h2>
<div class="grid">
    <input type="file" class="g-u" id="J_UploaderBtn" value="上传文件" name="Filedata" >
    <input type="hidden" id="J_Urls" name="urls" value="" />
</div>
<ul id="J_UploaderQueue">

</ul>
<p>
    <input class="btn" id="J_Add" type="button" value="添加一个文件">
    <input class="btn" id="J_DelFirst" type="button" value="删除第一个文件">
    <input class="btn" id="J_Clear" type="button" value="删除所有文件">
    <input class="btn" id="J_GetAll" type="button" value="获取所有文件id">
    <input class="btn" id="J_GetStatusFileIds" type="button" value="获取所有等待状态的文件id">
    <input class="btn" id="J_GetStatusFilesIndex" type="button" value="获取所有等待状态文件index">
</p>

<script type="text/javascript">
    var S = KISSY;
    if (S.Config.debug) {
        var srcPath = "../../../../";
        S.config({
            packages:[
                {
                    name:"gallery",
                    path:srcPath,
                    charset:"utf-8"
                }
            ]
        });
    }
    var $ = S.Node.all;

    S.use('gallery/uploader/1.5.4/index,gallery/uploader/1.5.4/themes/default/index,gallery/uploader/1.5.4/themes/default/style.css', function (S, Uploader,DefaultTheme) {
        //上传组件插件
        var plugins = 'gallery/uploader/1.5.4/plugins/auth/auth,' +
                'gallery/uploader/1.5.4/plugins/urlsInput/urlsInput,' +
                'gallery/uploader/1.5.4/plugins/proBars/proBars';

        S.use(plugins,function(S,Auth,UrlsInput,ProBars){
            var uploader = new Uploader('#J_UploaderBtn',{
                //处理上传的服务器端脚本路径
                action:"upload.php",
                multiple:true
            });
            //使用主题
            uploader.theme(new DefaultTheme({
                queueTarget:'#J_UploaderQueue'
            }))
            //验证插件
            uploader.plug(new Auth({
                        //最多上传个数
                        max:1,
                        //图片最大允许大小
                        maxSize:100
                    }))
                //url保存插件
                    .plug(new UrlsInput({target:'#J_Urls'}))
                //进度条集合
                    .plug(new ProBars())
            ;
            var queue = uploader.get('queue');

            $('#J_Add').on('click', function (ev) {
                //测试文件数据
                var testFile = {'name':'test.jpg',
                    'size':2000,
                    'input':{},
                    'file':{'name':'http://tp4.sinaimg.cn/1653905027/180/5601547226/1', 'type':'image/jpeg', 'size':2000}
                };
                //向队列添加文件
                var file = queue.add(testFile);
                S.log('添加的文件数据为：'+file);
            });
            $('#J_DelFirst').on('click', function (ev) {
                var removeFile = queue.remove(0);
                S.log('删除的文件数据为：'+removeFile);
            });
            $('#J_Clear').on('click', function (ev) {
                queue.clear();
            });
            $('#J_GetAll').on('click', function (ev) {
                var ids = [],
                        files = queue.get('files');
                S.each(files, function (file) {
                    ids.push(file.id);
                });
                alert('所有文件id：' + ids);
            });
            $('#J_GetStatusFileIds').on('click', function (ev) {
                var files = queue.getFiles('waiting'),
                        ids = [];
                S.each(files, function (file) {
                    ids.push(file.id);
                });
                alert('所有等待中的文件id为：' + ids);
            });
            $('#J_GetStatusFilesIndex').on('click', function () {
                var indexs = queue.getIndexs('waiting');
                alert('所有等待中的文件index为：' + indexs);
            })
        });
    })
</script>

</body>
</html>
